home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / CBGETRF.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  100 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)cbgetrf.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10.  
  11. /* library headers */
  12. #include <blkio.h>
  13. #include <lseq.h>
  14.  
  15. /* local headers */
  16. #include "cbase_.h"
  17.  
  18. /*man---------------------------------------------------------------------------
  19. NAME
  20.      cbgetrf - get cbase record field
  21.  
  22. SYNOPSIS
  23.      #include <cbase.h>
  24.  
  25.      int cbgetrf(cbp, field, buf)
  26.      cbase_t *cbp;
  27.      int field;
  28.      void *buf;
  29.  
  30. DESCRIPTION
  31.      The cbgetrf function reads the specified field from the current
  32.      record of cbase cbp into buf.  buf must point to a storage area
  33.      of size no less than the size of the specified field.
  34.  
  35.      cbgetrf will fail if one or more of the following is true:
  36.  
  37.      [EINVAL]       cbp is not a valid cbase pointer.
  38.      [EINVAL]       field is not a valid field number for
  39.                     cbase cbp.
  40.      [EINVAL]       buf is the NULL pointer.
  41.      [CBELOCK]      cbp is not read locked.
  42.      [CBENOPEN]     cbp is not open.
  43.      [CBENREC]      The record cursor for cbp is null.
  44.  
  45. SEE ALSO
  46.      cbcursor, cbgetr, cbputrf.
  47.  
  48. DIAGNOSTICS
  49.      Upon successful completion, a value of 0 is returned.  Otherwise,
  50.      a value of -1 is returned, and errno set to indicate the error.
  51.  
  52. ------------------------------------------------------------------------------*/
  53. #ifdef AC_PROTO
  54. int cbgetrf(cbase_t *cbp, int field, void *buf)
  55. #else
  56. int cbgetrf(cbp, field, buf)
  57. cbase_t *cbp;
  58. int field;
  59. void *buf;
  60. #endif
  61. {
  62.     /* validate arguments */
  63.     if (!cb_valid(cbp) || buf == NULL) {
  64.         errno = EINVAL;
  65.         return -1;
  66.     }
  67.  
  68.     /* check if not open */
  69.     if (!(cbp->flags & CBOPEN)) {
  70.         errno = CBENOPEN;
  71.         return -1;
  72.     }
  73.  
  74.     /* validate field argument */
  75.     if (field < 0 || field >= cbp->fldc) {
  76.         errno = EINVAL;
  77.         return -1;
  78.     }
  79.  
  80.     /* check if not read locked */
  81.     if (!(cbp->flags & CBRDLCK)) {
  82.         errno = CBELOCK;
  83.         return -1;
  84.     }
  85.  
  86.     /* check if cursor is null */
  87.     if (lscursor(cbp->lsp) == NULL) {
  88.         errno = CBENREC;
  89.         return -1;
  90.     }
  91.  
  92.     /* read field */
  93.     if (lsgetrf(cbp->lsp, cbp->fldv[field].offset, buf, cbp->fldv[field].len) == -1) {
  94.         CBEPRINT;
  95.         return -1;
  96.     }
  97.  
  98.     return 0;
  99. }
  100.